<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="javabean.Conn" %>
    <%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>login_deal</title>
</head>
<body>

<jsp:useBean id="user_login" class="javabean.User"></jsp:useBean>
<jsp:setProperty property="*" name="user_login"/>
<%
try{
	session.setAttribute("login_name",user_login.getName());
	Connection conn=Conn.connect();
	String selectsql="select * from wuqiantong where name=?";
	PreparedStatement ps=conn.prepareStatement(selectsql);
	ps.setString(1,user_login.getName());
	ResultSet rs=ps.executeQuery();
	if(rs.next()){
	    if(rs.getString(4).equals("imadmin")){
	    	response.sendRedirect("adminMain.jsp");
	    }
		else if(rs.getString(4).equals(user_login.getPassword())){
			response.sendRedirect("main.jsp");
		}
		else{
			out.print("Your password is wrong.");
		}
	}
	else{
		out.print("You haven't register.");
	}
	rs.close();
	ps.close();
	conn.close();
}
catch(Exception e){
	e.printStackTrace();
	out.print("Login failed.");
}
%>
<a href="login.jsp">back</a>
</body>
</html>